<?php
/**
 * @category 	AnniversaryDao.php
 * @author 		Sung Hoon, Cho (akdddnet@gmail.com)
 * @since		2011. 4. 1.
 * @license		BSD License
 * @version		0.1
 */

global $CFG;
require_once $CFG->FW_DIR."/mvc/Dao.php";
 
class AnniversaryDao extends Dao {
	
 	function __construct(array $db_type = null) {
 		parent::__construct($db_type);	
 	}
 	
 	function index(DTO $dto) {
 		$query = "
 				SELECT 
 							*
 				FROM 		anniversary
 				WHERE		1 = 1
 		";

 		$dto->list = $this->db->query($query)->fetchAll();
 		
 		return $dto;
 	}
 	
 	function view(DTO $dto) {
 		$query ="
 				SELECT		*
 				FROM 		anniversary
 				WHERE		1 = 1
 				AND			ay_seq = :ay_seq
 		";
 		
 		$bind = array(
 				"ay_seq"=>$dto->eb->ay_seq
 		);
 		
 		$dto->obj = $this->db->query($query, $bind)->fetch();
 		
 		return $dto;
 	}
 	
 	function doAdd(DTO $dto) {
 		$query = "
 				INSERT INTO anniversary
 					(ay_name, ay_date, ay_is_solar, ay_main, ay_display)
 				VALUES
 					(:ay_name, date(:ay_date), :ay_is_solar, :ay_main, :ay_display)
 		";
 		
 		$bind = array(
 			 "ay_name"=>$dto->eb->ay_name
 			,"ay_date"=>$dto->eb->ay_date
 			,"ay_is_solar"=>$dto->eb->ay_is_solar
 			,"ay_main"=>$dto->eb->ay_main
 			,"ay_display"=>$dto->eb->ay_display
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	
	function doModify(DTO $dto) {
 		$query = "
 				UPDATE 	anniversary SET
	 					 ay_name 		= :ay_name
	 					,ay_date			= date(:ay_date)
	 					,ay_is_solar		= :ay_is_solar
	 					,ay_main 		= :ay_main
	 					,ay_display		= :ay_display
 				WHERE	1 = 1
 				AND		ay_seq			= :ay_seq
 		";
 		
 		$bind = array(
 			 "ay_seq"=>$dto->eb->ay_seq
 			,"ay_name"=>$dto->eb->ay_name
 			,"ay_date"=>$dto->eb->ay_date
 			,"ay_is_solar"=>$dto->eb->ay_is_solar
 			,"ay_main"=>$dto->eb->ay_main
 			,"ay_display"=>$dto->eb->ay_display
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	function doDelete(DTO $dto) {
 		$query = "
 			DELETE 
 			FROM 	anniversary 
 			WHERE	1 = 1
			AND		ay_seq = :ay_seq  			
 		";
 		
 		$bind = array(
 			"ay_seq"=>$dto->eb->ay_seq
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	
 	function getLunarToSolar(DTO $dto) {
 		$query = "
 			SELECT 
 						* 
 			FROM 		lunartosolar 
 			WHERE		1 = 1
 			AND			lunar_date = :lunar_date
 		";
 		
 		$bind = array(
 			"lunar_date"=>$dto->obj
 		);
 		
 		$dto->obj = $this->db->query($query, $bind)->fetch();
 		
 		return $dto;
 	}
}